package com.ruoyi.school.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.school.domain.PacFaculties;
import com.ruoyi.school.service.PacFacultiesService;
import com.ruoyi.school.mapper.PacFacultiesMapper;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
* @author jeremylin
* @description 针对表【pac_faculties(学院表)】的数据库操作Service实现
* @createDate 2025-05-25 17:35:22
*/
@Service
public class PacFacultiesServiceImpl extends ServiceImpl<PacFacultiesMapper, PacFaculties>
    implements PacFacultiesService{

    /**
     * 获取所有的学院信息
     *
     * @param pacFaculties
     * @return
     */
    @Override
    public List<PacFaculties> all(PacFaculties pacFaculties) {
        return lambdaQuery().list();
    }

    /**
     * 保存学院信息
     *
     * @param pacFaculties
     */
    @Override
    public void saveOne(PacFaculties pacFaculties) {
        if(pacFaculties.getFacultiesName() != null){
            PacFaculties one = lambdaQuery().eq(PacFaculties::getFacultiesName, pacFaculties.getFacultiesName()).one();
            if(one == null){
                save(pacFaculties);
            }
        }
    }

    /**
     * 根据学院名字查询
     *
     * @param faculties
     * @return
     */
    @Override
    public PacFaculties getInfoByFacultiesName(String faculties) {
        if(faculties == null){
            return null;
        }
        PacFaculties one = lambdaQuery().eq(PacFaculties::getFacultiesName, faculties).one();
        return one;
    }

    @Override
    public List<PacFaculties> getList(PacFaculties pacCollege) {
        return lambdaQuery().eq(Objects.nonNull(pacCollege.getCollegeId()),PacFaculties::getCollegeId, pacCollege.getCollegeId()).list();
    }

    @Override
    public PacFaculties getDetails(PacFaculties pacCollege) {
        if(pacCollege.getId() == null){
            throw new RuntimeException("id不能为空");
        }
        PacFaculties one = lambdaQuery().eq(PacFaculties::getId, pacCollege.getId()).one();
        return one;
    }

    @Override
    public boolean add(PacFaculties pacCollege) {
        if(save(pacCollege)){
            return true;
        }
        return false;
    }

    @Override
    public boolean edit(PacFaculties pacCollege) {
        if(pacCollege.getId() == null){
            throw new RuntimeException("id不能为空");
        }
        if(updateById(pacCollege)){
            return true;
        }
        return false;
    }

    @Override
    public boolean delete(PacFaculties pacCollege) {
        if(pacCollege.getId() == null){
            throw new RuntimeException("id不能为空");
        }
        if(removeById(pacCollege)){
            return true;
        }
        return false;
    }
}




